﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Web.Security;

namespace WebApplication1
{
    public partial class NestedMasterPage1 : System.Web.UI.MasterPage
    {
        protected HyperLink lnklout = new HyperLink();

        protected void Page_Load(object sender, EventArgs e)
        {
            lnklout.ID = "lnkout";
            lnklout.NavigateUrl = "logout.aspx";
            lnklout.Text = "LogOut";
            Place1.Controls.Add(lnklout);

            //code to logout

            //code to logout
            // This Code is used to Disable the Browser "BACK Button"
            Response.ClearHeaders();
            Response.AppendHeader("Cache-Control", "no-cache"); //HTTP 1.1
            Response.AppendHeader("Cache-Control", "private"); // HTTP 1.1
            Response.AppendHeader("Cache-Control", "no-store"); // HTTP 1.1
            Response.AppendHeader("Cache-Control", "must-revalidate"); // HTTP 1.1
            Response.AppendHeader("Cache-Control", "max-stale=0"); // HTTP 1.1
            Response.AppendHeader("Cache-Control", "post-check=0"); // HTTP 1.1
            Response.AppendHeader("Cache-Control", "pre-check=0"); // HTTP 1.1
            Response.AppendHeader("Pragma", "no-cache"); // HTTP 1.1
            Response.AppendHeader("Keep-Alive", "timeout=3, max=993"); // HTTP 1.1
            Response.AppendHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT"); // HTTP 1.1

            //This code is used to maintain UserName in the Home page using Session and Cookies

            if (Session["name"] == null)
            {
                Response.Redirect("~/log.aspx");
            }
            else
            {
                IEnumerator mc;
                mc = Request.Cookies.AllKeys.GetEnumerator();
                while (mc.MoveNext())
                {
                    if (Request.Cookies[mc.Current.ToString()].HasKeys == true)
                    {
                        IEnumerator sc;
                        sc = Request.Cookies[mc.Current.ToString()].Value.GetEnumerator();
                        while (sc.MoveNext())
                        {
                            Response.Write(sc.Current.ToString() + Request.Cookies[mc.Current.ToString()][sc.Current.ToString()]);
                        }
                    }
                }
            }
        }

        //This Code is for the LOGOUT Code

        protected void lnkout_Click(object sender, EventArgs e)
        {
            Session.Clear();
            Session.RemoveAll();
            Session.Abandon();
            FormsAuthentication.SignOut();
            Response.Redirect("~/log.aspx", true);

        }
    }

}